let express = require('express');
let app = express();
let path = require('path');
let bodyParser = require('body-parser');
let session = require('./common/session');
//let auth = require('./middleware/auth');
let params = require('./middleware/params');
let morgan = require('./middleware/morgan');


app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.engine('html', require('ejs-mate'));

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(session);
//app.use(auth);
app.use(params);
app.use(morgan);

app.post('/session-test', function (req, res) {
  console.log(req.sessionID);
  res.send(req.sessionID);
});

//新增路由
app.use('/', require('./routes/routes_api'));

module.exports = app;

// let http = require('http');
//
// let port = normalizePort(process.env.PORT || '3000');
// app.set('port', port);
//
// let server = http.createServer(app);
// server.listen(port);
//
// function normalizePort(val) {
//   let port = parseInt(val, 10);
//
//   if (isNaN(port)) {
//     // named pipe
//     return val;
//   }
//
//   if (port >= 0) {
//     // port number
//     return port;
//   }
//
//   return false;
// }